package com.ad.pet.app.account.share;

import android.app.Activity;

import com.ad.pet.api.ApiService;
import com.ad.pet.app.RxDisposable;
import com.ad.pet.common.data.http.AppSubscriber;
import com.ad.pet.common.structure.mvp.AbsBasePresenter;
import com.ad.pet.models.remote.CommList;
import com.ad.pet.models.remote.account.share.ShareEndItem;
import com.ad.pet.models.remote.home.HomeMall;

import java.util.List;

import javax.inject.Inject;

/**
 * Created by liuyixiang on 2019/9/21.
 */

public class SharePresenter extends AbsBasePresenter implements ShareContracts.Presenter{

    private ApiService mApiService;
    private ShareContracts.View mView;

    private Activity mActivity;

    private RxDisposable mRxDisposable;

    @Inject
    public SharePresenter(ApiService apiService,
                            Activity activity, RxDisposable rxDisposable) {
        mApiService = apiService;
        mActivity = activity;
        mRxDisposable = rxDisposable;
    }



    @Override
    public void onDestroy() {
        if (mRxDisposable != null)
            mRxDisposable.clear();
        if (mActivity != null) mActivity = null;
        mView = null;
    }

    @Override
    public void onCreate(ShareContracts.View view) {
        this.mView = view;
    }







    @Override
    public void app_share_friend_data() {
        mRxDisposable.add(mApiService.app_share_friend_data()
                .subscribe(new AppSubscriber<ShareEndItem>(mView) {
                    @Override
                    public void next(ShareEndItem keyWord) {
                        mView.app_share_friend_dataSuccess(keyWord);
                    }
                }));
    }

    @Override
    public void app_share_product_data() {
        mRxDisposable.add(mApiService.app_share_product_data()
                .subscribe(new AppSubscriber<ShareEndItem>(mView) {
                    @Override
                    public void next(ShareEndItem keyWord) {
                        mView.app_share_product_dataSuccess(keyWord);
                    }
                }));
    }

    @Override
    public void viewListRecord() {
        mRxDisposable.add(mApiService.get_track_product_list()
                .subscribe(new AppSubscriber<CommList<List<HomeMall>>>(mView) {
                    @Override
                    public void next(CommList<List<HomeMall>> keyWord) {
                        mView.viewListRecordSuccess(keyWord.getProduct_list());
                    }
                }));
    }
}
